package com.icim.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.icim.entity.BisMItem;

@Repository
public class BisMItemDao {
    @Resource
    private JdbcTemplate icimJdbcTemplate;

	public List<BisMItem> getAllbisMItemByToolIdAndMesId(String tool_id_fk, String mdl_id_fk) {
		String sql="SELECT DATA_ID,DATA_GROUP,L_SPEC,U_SPEC FROM BIS_M_ITEM WHERE TOOL_ID_FK=? and MES_ID_FK=?";
		return icimJdbcTemplate.query(sql, new String[]{tool_id_fk,mdl_id_fk}, new RowMapper<BisMItem>(){

			@Override
			public BisMItem mapRow(ResultSet rs, int rowNum) throws SQLException {
				BisMItem bisMItem=new BisMItem();
				int temp=Integer.parseInt(rs.getString("DATA_ID"));
				bisMItem.setDataId(String.format("%03d", temp+1));
				bisMItem.setDataGroup(rs.getString("DATA_GROUP"));
				bisMItem.setlSpc(rs.getDouble("L_SPEC"));
				bisMItem.setuSpc(rs.getDouble("U_SPEC"));
				return bisMItem;
			}
			
		});
	}
}
